package com.wenguo.action.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.wenguo.Constants;
import com.wenguo.bussines.model.Log;
import com.wenguo.bussines.model.User;
import com.wenguo.common.util.BeansUtil;
import com.wenguo.common.util.URLHelper;
import com.wenguo.common.util.URLHelper.PageInfo;
import com.wenguo.exception.WenGuoException;


@Controller
@RequestMapping("/log/*")
public class LogAction extends BaseAction {

	@RequestMapping(value="list/{page}",method=RequestMethod.GET)
	public String profile(User user, @PathVariable String page, HttpServletRequest request, Model model){
		try {
			PageInfo pageInfo = URLHelper.getPageInfo(request);
			Log log = new Log();
			log.setUser(BeansUtil.getLoginUser(request));
			Long total = facade.findCountOfLog(log);
			pageInfo.setTotalCount(total);
			model.addAttribute(Constants.system.PAGE_BEAN, pageInfo);
			
			List<Log> logList = facade.findLogByPage(BeansUtil.getLogQueryParams(pageInfo, request));
			model.addAttribute(Constants.system.TAG_LIST, logList);
			return "log/list";
		} catch (WenGuoException e) {
			logger.error(e);
		}
		model.addAttribute(Constants.system.TIPS, "get log list exception");
		return "log/list";
	}
	
}
